package com.leef.oauth.data.pojo;

import android.util.Base64;

import com.alibaba.fastjson.annotation.JSONField;
import com.leef.oauth.util.DESedeCoder;


/**
 * Created by IWALL on 2017/3/13.
 * The JSONString Contain Security Key
 * {"encRes":"h/EMCrLOCxZXK5ABC6nG0nfpEv6BlJODvhGo5yQUXmU87oqbYmbDlDfFvRKwcV0K"}
 */

public class Key {
    public static String SESSION64 = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4";

    @JSONField(name = "encRes")
    private String encRes;

    public Key() {
    }

    public String getEncRes() {
        return encRes;
    }

    public void setEncRes(String encRes) {
        this.encRes = encRes;
    }

    public String getKey() {
        String key = null;
        try {
            byte[] session = DESedeCoder.toKey(Base64.decode(SESSION64, Base64.DEFAULT)).getEncoded();
            byte[] dec = DESedeCoder.decrypt(Base64.decode(encRes, Base64.DEFAULT), session);
            key = new String(dec);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return key;
    }
}
